package org.example.coursemangementserver.server.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.coursemangementserver.common.result.Result;
import org.example.coursemangementserver.pojo.dto.IDListDTO;
import org.example.coursemangementserver.pojo.dto.course.*;
import org.example.coursemangementserver.pojo.dto.course.StudentCommentListQuery.GetStudentCommentListDTO;
import org.example.coursemangementserver.pojo.dto.course.TeacherCourseQuery.GetTeacherCourseListDTO;
import org.example.coursemangementserver.pojo.dto.student.StudentNewInfoDTO;
import org.example.coursemangementserver.pojo.dto.student.TeacherGetStudentOnCourseListDTO;
import org.example.coursemangementserver.pojo.dto.teacher.RemoveStudentFromCourseDTO;
import org.example.coursemangementserver.pojo.dto.teacher.TeacherNewInfoDTO;
import org.example.coursemangementserver.pojo.vo.course.StudentCommentList.StudentCommentListVO;
import org.example.coursemangementserver.pojo.vo.course.TeacherCourseList.TeacherCourseListVO;
import org.example.coursemangementserver.pojo.vo.student.TeacherGetStudentListOnCourse.StudentListVO;
import org.example.coursemangementserver.pojo.vo.teacher.TeacherInfoVO;
import org.example.coursemangementserver.server.service.interfac.teacher.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 与老师操作相关的请求
 * @author 12438
 */
@RestController
@Slf4j
@RequestMapping("/teacher")
public class teacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * 处理老师获取自己所授课程信息的请求
     */
    @PostMapping("/getTeacherCourseList")
    public Result<TeacherCourseListVO> getTeacherCourseList(@RequestBody GetTeacherCourseListDTO getTeacherCourseListDTO) {
        TeacherCourseListVO teacherCourseListVO = teacherService.getTeacherCourseList(getTeacherCourseListDTO);
        return Result.success(teacherCourseListVO);
    }

    /**
     * 处理老师获取自己所授课程的评价的请求
     */
    @PostMapping("/getStudentCommentList")
    public Result<StudentCommentListVO> getStudentCommentList(@RequestBody GetStudentCommentListDTO getStudentCommentListDTO) {
        StudentCommentListVO studentCommentListVO = teacherService.getStudentCommentList(getStudentCommentListDTO);
        return Result.success(studentCommentListVO);
    }

    /**
     * 处理老师获取自己个人信息的请求
     */
    @PostMapping("/getTeacherDetail")
    public Result<TeacherInfoVO> getTeacherDetail() {
        TeacherInfoVO teacherInfoVO = teacherService.getTeacherDetail();
        return Result.success(teacherInfoVO);
    }

    /**
     * 老师更新自己的个人信息
     */
    @PostMapping("/updateTeacherInfo")
    public Result updateTeacherInfo(@RequestBody TeacherNewInfoDTO teacherNewInfoDTO) {
        teacherService.updateTeacherInfo(teacherNewInfoDTO);
        return Result.success();
    }

    /**
     * 老师结束自己所教的课程
     */
    @PostMapping("/endCourse")
    public Result updateTeacherInfo(@RequestBody EndCourseDTO endCourseDTO) {
        teacherService.endCourse(endCourseDTO);
        return Result.success("结课成功");
    }

    /**
     * 老师查看自己课程中的学生信息
     */
    @PostMapping("/getCourseStudentList")
    public Result<StudentListVO> getCourseStudentList(@RequestBody TeacherGetStudentOnCourseListDTO teacherGetStudentOnCourseListDTO) {
        StudentListVO studentListVO = teacherService.getCourseStudentList(teacherGetStudentOnCourseListDTO);
        return Result.success(studentListVO);
    }

    /**
     * 老师移除自己课程中的学生信息
     */
    @PostMapping("/removeStudentFromCourse")
    public Result removeStudentFromCourse(@RequestBody RemoveStudentFromCourseDTO removeStudentFromCourseDTO) {
        teacherService.removeStudentFromCourse(removeStudentFromCourseDTO);
        return Result.success("移除成功");
    }

    /**
     * 老师删除学生对自己课程的评价信息
     */
    @PostMapping("/deleteCourseReview")
    public Result deleteCourseReview(@RequestBody TeacherDeleteCourseReviewDTO teacherDeleteCourseReviewDTO) {
        teacherService.deleteCourseReview(teacherDeleteCourseReviewDTO);
        return Result.success("移除成功");
    }

    /**
     * 老师为自己的课程添加学生
     * @return
     */
    @PostMapping("/teacherAddStudentToCourse")
    public Result teacherAddStudentToCourse(@RequestBody TeacherAddStudentToCourse teacherAddStudentToCourse){
        teacherService.teacherAddStudentToCourse(teacherAddStudentToCourse);
        return Result.success();
    }

    /**
     * 老师编辑课堂信息
     * @return
     */
    @PostMapping("/updateSelectCourse")
    public Result updateSelectCourse(@RequestBody UpdateEnrollmentDTO updateEnrollmentDTO){
        log.info("教师编辑选课：{}",updateEnrollmentDTO);
        teacherService.updateSelectCourse(updateEnrollmentDTO);
        return Result.success("成功");
    }

    @PostMapping("/getEnrollmentCommentList")
    public Result <StudentCommentListVO> getEnrollmentCommentList(@RequestBody GetEnrollmentCommentDTO getEnrollmentCommentDTO){
        StudentCommentListVO studentCommentListVO = teacherService.getEnrollmentCommentList(getEnrollmentCommentDTO);
        return Result.success(studentCommentListVO);
    }
}
